/**
 * 
 */
package com.sapient.service.operation;

import java.util.HashMap;
import java.util.Map;

import com.sapient.service.ServiceException;

public class OperationFactory {

	private static final String MULTIPLY = "multiplied";

	private static final String MINUS = "minus";

	private static final String PLUS = "plus";
	
	private Map<String, Operation> operationMap = new HashMap<String, Operation>();
	
	public OperationFactory() {
		operationMap.put(PLUS, new Operation() {
			
			public int compute(final int firstNumber, final int secondNumber) {
				return firstNumber + secondNumber;
			}

			public String getName() {
				return PLUS;
			}
		});
		operationMap.put(MINUS, new Operation() {
			
			public int compute(final int firstNumber, final int secondNumber) {
				return firstNumber - secondNumber;
			}
			
			public String getName() {
				return MINUS;
			}
		});
		operationMap.put(MULTIPLY, new Operation() {
			
			public int compute(final int firstNumber, final int secondNumber) {
				return firstNumber * secondNumber;
			}
			
			public String getName() {
				return MULTIPLY;
			}
		});
	}
	public Operation getOperationHandler(final String operationName) throws ServiceException{
		return operationMap.get(operationName); 
	}
}
